<?php
/**
 * Created by PhpStorm.
 * User: idcu
 * Date: 2016/3/8
 * Time: 17:56
 */
namespace Service\Controller;
use Admin\Controller\AdminController;

class CustomerController extends AdminController
{
    public function telSearch(){
        $req = $this->getReq();
        $tel = $req['tel'];
        $where['tel'] = $tel;
        $where['attestation_tel'] = $tel;
        $where['_logic'] = 'or';
        $data1 = D($this->model)->where($where)->relation('families')->find();
        $data2 = D($this->model)->where(array('contact'=>array('like','%'.$req['tel'].'%')))->relation('families')->select();
        if(!$data2){
            $res = array();
        }else{
            foreach($data2 as $k=>$v){
                $data2[$k]['paimary'] = 0;
            }
            $res = $data2;
        }
        if($data1){
            $data1['primary'] = 1;
            array_unshift($res,$data1);
        }
        $this->ajaxReturn($res);
    }
}